package com.bytz.modules.cms.domain.impl.price;

import com.bytz.modules.cms.domain.model.price.PriceComputeContext;
import com.bytz.modules.cms.domain.model.price.PriceComputeResult;
import com.bytz.modules.cms.reseller.constant.ResellerConstant;
import com.bytz.modules.cms.reseller.entity.ResellerProduct;
import com.bytz.modules.cms.reseller.service.IResellerProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 经销商限制产品计算器，顺序3
 * @author shanxuezhong
 */
@Component
public class ResellerLimitComputer extends AbstractPriceComputer {
    @Autowired
    private IResellerProductService resellerProductService;

    @Override
    public void doCompute(PriceComputeContext context) {
        ensureResellerProducts(resellerProductService, context);

        Map<String, PriceComputeResult> results = context.getResults();
        for (ResellerProduct resellerProduct : context.getResellerProducts()) {
            if (ResellerConstant.ResellerProductOffsetType.NO_PRICE.equals(resellerProduct.getOffsetType())) {
                PriceComputeResult priceComputeResult = results.get(resellerProduct.getProductNumber());
                if (priceComputeResult != null) {
                    priceComputeResult.setPrice(null);
                }
            }
        }
    }

    @Override
    public void afterCompute(PriceComputeContext context) {
        super.afterCompute(context);
    }
}
